//
//  SettingViewController.swift
//  爱限免
//
//  Created by 曲晨阳的MacBook on 16/9/29.
//  Copyright © 2016年 QCY. All rights reserved.
//

//设置界面
import UIKit

class SettingViewController: LFNavViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
        
        //导航
        createMyNav()
        
        //按钮
        createButtons()
    }
    
    //导航
    func createMyNav()
    {
        //返回按钮
        addBackButton()
        //标题
        addNavTitle("设置")
        //按钮
        createButtons()
    }
    
    //创建按钮
    func createButtons()
    {
        let imageArray = ["account_setting","account_favorite","account_user","account_collect","account_download","account_comment","account_help","account_candou"]
        let titleArray = ["我的设置","我的关注","我的帐号","我的收藏","我的下载","我的评论","我的帮助","蚕豆应用"]
        
        //循环创建按钮
        let colNum = 3              //列数
        let btnW: CGFloat = 60      //按钮宽度
        let btnH: CGFloat = 60      //按钮高度
        let titleH: CGFloat = 20    //文字高度
        let offSetX: CGFloat = 50   //第一个按钮左边的间距
        let offSetY: CGFloat = 160
        //列间距
        let spaceX: CGFloat = (kScreenWidth-offSetX*2-btnW*CGFloat(colNum))/(CGFloat(colNum-1))  //（屏款－2*间距－列数*按钮宽度）／ （列数－1）
        let spaceY: CGFloat = 80  //按钮之间的行间距
        for i in 0..<imageArray.count
        {
            //计算行号和列号
            let row = i/colNum
            let col = i%colNum
            let btnX = offSetX + (btnW+spaceX)*CGFloat(col)
            let btnY = offSetY + (btnH+titleH+spaceY)*CGFloat(row)
            //1)按钮
            let button = UIButton.createButton(CGRectMake(btnX, btnY, btnW, btnH), title: nil, bgImageName: imageArray[i], target: self, action: #selector(clickButton(_:)))
            button.tag = 200 + i
            self.view.addSubview(button)
            
            //2)文字
            let label = UILabel.createLabelFrame(CGRectMake(btnX, btnY+btnH, btnW, titleH), title: titleArray[i], textAlignment: .Center)
            label.font = UIFont.systemFontOfSize(12)
            self.view.addSubview(label)
        }
    }
    
    func clickButton(btn: UIButton)
    {
        let index = btn.tag - 200
        if index == 3  //收藏
        {
            let collectCtrl = CollectViewController()
            hidesBottomBarWhenPushed = true
            navigationController?.pushViewController(collectCtrl, animated: true)
            hidesBottomBarWhenPushed = false
        }
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
